type IStations = {
  label: string;
  value: string;
};

const getStation = (station: any[], currentMarketId: string): IStations[] => {
  const list: IStations[] = [];
  const currentMarketInfo = station.find((item) => item.marketId === currentMarketId);
  if (currentMarketInfo) {
    const recursion = (arr: any[]) => {
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].children && arr[i].children.length > 0) {
          recursion(arr[i].children);
        }
        if (!arr[i].children || arr[i].children.length === 0) {
          list.push({
            label: arr[i].stationName,
            value: arr[i].stationId,
          });
        }
      }
    };
    recursion(currentMarketInfo.children);
  }

  return list;
};

export { getStation };
